﻿// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Oliver Rau" email="mail@olira.de"/>
//     <version>$Revision: 9 $</version>
//     <created>11.08.2006 20:17</created>
// </file>

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

using ICSharpCode.Core;

namespace ns2kml
{
	/// <summary>
	/// Description of FrmMain.
	/// </summary>
	public partial class FrmMain
	{
		public FrmMain()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
		}
		
		void BtnSelectTargetClick(object sender, System.EventArgs e)
		{
			using (FolderBrowserDialog fbd = new FolderBrowserDialog()) {
				fbd.Description = "Please select the target folder:";
				
				if (fbd.ShowDialog() == DialogResult.OK) {
					txtTargetDirectory.Text = fbd.SelectedPath;
				}
			}
		}
		
		void BtnGenerateClick(object sender, System.EventArgs e)
		{
			if (!Directory.Exists(txtTargetDirectory.Text))
				throw new DirectoryNotFoundException();
			
			List<string> files = new List<string>();;
			
			foreach (string item in lstSources.Items) {
				files.Add(item);
			}
			
			KmlHelper.GenerateKmlRecursive(files, txtTargetDirectory.Text);
			
			MessageBox.Show("Done!");
		}
		

		
		void BtnAddSourceClick(object sender, System.EventArgs e)
		{
			using (OpenFileDialog ofd = new OpenFileDialog()) {
				ofd.Title = "Select the source file";
				ofd.Filter = "Netstumbler files (*.ns1)|*.ns1|Text files (*.txt)|*.txt|All Files (*.*)|*.*";
				ofd.CheckFileExists = true;
				ofd.Multiselect = true;
				
				if (ofd.ShowDialog() == DialogResult.OK) {
					foreach (string fileName in ofd.FileNames) {
						lstSources.Items.Add(fileName);
						if (txtTargetDirectory.Text == "")
							txtTargetDirectory.Text = Path.GetDirectoryName(fileName);
					}
					
				}
			}
		}
		
		void BtnRemoveSourceClick(object sender, System.EventArgs e)
		{
			foreach (object item in lstSources.SelectedItems) {
				lstSources.Items.Remove(item);
			}
		}
	}
}
